package cn.fjy.android.phone.worker;


import android.media.AudioManager;
import android.media.ToneGenerator;
import android.os.Vibrator;
import android.telephony.TelephonyManager;
import android.util.Log;

/**
 * @author GrayF
 * @2011-3-31
 */
public class TalkTimeRemind implements Runnable {

//	private String tag = "TalkTimeRemind";

	// 提示方式为震动
	public final static int REMIND_TYPE_VIBRATOR = 0;

	// 提示方式为提示音
	public final static int REMIND_TYPE_AUDIO = 1;

	// 提示方式
	public int remind_type = REMIND_TYPE_AUDIO;

	// 是否启用该功能
	public boolean isEnable = false;

	public int tt_vibrator_time = 100;
	
	private int tone_type = 12;

	private int tone_sed = 200;
	
	private long sleepTime = 45000;
	

	// 震动器
	private Vibrator vibrator;
	
	private TelephonyManager telManager;
	
	public TalkTimeRemind(Vibrator vibrator,int type,TelephonyManager telManager) {
		this.vibrator = vibrator;
		remind_type = type;
		this.telManager = telManager;
	}

	@Override
	public void run() {
			while(isEnable){
				try {
					Thread.sleep(sleepTime);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				if(telManager.getCallState()==TelephonyManager.CALL_STATE_IDLE){
					break;
				}
				if (isEnable) {
					sleepTime = 60000;
					Log.i("PhoneStateService", "45秒提示");
					if (remind_type == REMIND_TYPE_VIBRATOR) {
						vibrator.vibrate(100);
					} else {
						ToneGenerator mToneGenerator = new ToneGenerator(
								AudioManager.STREAM_MUSIC, 80);
						mToneGenerator.startTone(tone_type, tone_sed);
						mToneGenerator.startTone(tone_type, tone_sed);
					}
				}
			}
	}
	
	public boolean isEnable() {
		return isEnable;
	}

	public void setEnable(boolean isEnable) {
		this.isEnable = isEnable;
	}

}
